package us.versus.them.hmap;

import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.MouseEvent;

class ImageDemo extends MovieClip {
	var images : Hash< DisplayObject >;

	public static function main() {
		flash.Lib.current.addChild( new ImageDemo( ImageDemo.imageNameArray() ) );
	}

	public function new ( images : Array< String > ) {
		super();
		( new MultipleLoader( "demo" ) ).load( images, onComplete );
	}

	public function onComplete( name : String, images : Hash< DisplayObject > ) {
		this.images = images;
		flash.Lib.current.addEventListener( MouseEvent.CLICK, click );
		this.click();
	}

	public function click( ?x : Dynamic ) {
		for ( key in images.keys() ) {
			var image : DisplayObject = images.get( key );
			var movieClip : MovieClip = new MovieClip();
			movieClip.x = Math.random() * 400;
			movieClip.y = Math.random() * 400;
			movieClip.addChild( image );
			this.addChild( movieClip );
		}
	}

	public static function imageNameArray() : Array< String > {
		var imageNames : Array< String > = new Array< String >();
		imageNames.push( "images/baker-add-dir.png" );
		imageNames.push( "images/baker-add-files.png" );
		imageNames.push( "images/baker-audio-copy.png" );
		imageNames.push( "images/baker-blank-cdrw.png" );
		imageNames.push( "images/baker-blank-dvdrw.png" );
		imageNames.push( "images/baker-burn-cd.png" );
		imageNames.push( "images/baker-cd-iso.png" );
		imageNames.push( "images/baker-cd.png" );
		imageNames.push( "images/baker-cue-image.png" );
		imageNames.push( "images/baker-data-copy.png" );
		imageNames.push( "images/baker-dvd-iso.png" );
		imageNames.push( "images/baker-import-session.png" );
		imageNames.push( "images/baker-remove-files.png" );
		imageNames.push( "images/gnomebaker-48.png" );
		return imageNames;
	}
}
